//
//  UIBarButtonItem+Extension.swift
//  HrenryWeibo
//
//  Created by 熊涛 on 16/5/15.
//  Copyright © 2016年 熊涛. All rights reserved.
//

import UIKit

extension UIBarButtonItem {


    
    convenience init(imageName : String, target: AnyObject?, selector : Selector) {
        //创建一个button
        let button = UIButton(type: UIButtonType.Custom)
        //设置图片
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: (imageName + "_highlighted")), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        //添加事件
        button.addTarget(target, action: selector, forControlEvents: UIControlEvents.TouchUpInside)
    
        self.init(customView : button)
    }

}